import type { ProColumns } from '@ant-design/pro-table';
import { getActionName } from './service'

// 定义请求返回数据类型
export type ColumnsItem = {
  acNo: string;
  actionCode: string;
  actionName: string;
  balance: number;
  createdTime: Date;
  custNo: string;
  effTime: Date;
  failTime: Date;
  point: number;
  remarks: string;
  srcTxNo: string;
  status: string;
  txNo: string;
  txResult: string;
  txTime: Date;
  txType: string;
}


// 定义表头
let columnsData: ProColumns<ColumnsItem>[] = [
  {
    title: '获赠会员号',
    dataIndex: 'custNo',
    hideInTable: true,
    fieldProps: {
      maxLength: 20
    },
  },
  {
    title: '获赠规则',
    dataIndex: 'actionCode',
    hideInTable: true,
    valueType: 'select',
    request: (a) => getActionName({}).then((res: any) => {
      let data: any = [];
      res.body.filter((item: any) => item).map((item: any, index: number) => {
        data[index] = {
          value: item.actionCode,
          label: item.actionName
        }
      })
      return data
    })
  },
  {
    title: '交易日期',
    hideInTable: true,
    dataIndex: 'date',
    valueType: 'dateRange',
    search: {
      transform: (value) => {
        return {
          startDate: value[0],
          endDate: value[1],
        };
      },
    },
  },
  {
    title: '交易流水号',
    dataIndex: 'txNo',
    hideInTable: true,
    fieldProps: {
      maxLength: 20
    },
  },
  {
    title: '交易种类',
    dataIndex: 'txType',
    hideInTable: true,
    valueType: 'select',
    valueEnum: {
      0: { text: '激励', status: 'Success' },
      1: { text: '失效', status: 'Failure ' },
    },
  },

  // 上方查询，下方表头
  {
    title: '序号',
    dataIndex: 'index',
    valueType: 'indexBorder',
    width: 50,
    fixed: 'left',
  },
  {
    title: '获赠会员号',
    width: 120,
    fixed: 'left',
    hideInSearch: true,
    dataIndex: 'custNo',
    ellipsis: true,
  },
  {
    title: '积分账号',
    width: 160,
    hideInSearch: true,
    dataIndex: 'acNo',
  },
  {
    title: '交易积分',
    width: 160,
    hideInSearch: true,
    dataIndex: 'point',
  },
  {
    title: '交易种类',
    width: 100,
    hideInSearch: true,
    dataIndex: 'txType',
    valueType: 'select',
    valueEnum: {
      0: {
        text: '激励',
        status: 'Success',
      },
      1: {
        text: '失效',
        status: 'Error',
      }
    },
  },
  {
    title: '获赠行为名称',
    width: 120,
    hideInSearch: true,
    dataIndex: 'actionName',
    ellipsis: true,
  },
  {
    title: '获赠行为编号',
    width: 180,
    hideInSearch: true,
    dataIndex: 'actionCode',
  },
  {
    title: '交易日期',
    width: 160,
    hideInSearch: true,
    dataIndex: 'txTime',
  },
  {
    title: '积分余额',
    width: 160,
    hideInSearch: true,
    dataIndex: 'balance',
  },
  {
    title: '交易流水号',
    width: 180,
    hideInSearch: true,
    dataIndex: 'txNo',
  },
  {
    title: '交易结果',
    hideInSearch: true,
    dataIndex: 'txResult',
    width: 100,
    valueType: 'select',
    valueEnum: {
      0: {
        text: '成功',
        status: 'Success',
      },
      1: {
        text: '失效',
        status: 'Error',
      }
    },
  },
  {
    title: '失败原因',
    width: 160,
    dataIndex: 'remarks',
    hideInSearch: true,
  }
]
export default columnsData;
